﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Com.Toook.Common;
using System.Data.OleDb;

public partial class movie_list : BaseShowPage
{
    private int pageSize = 10;
    protected string PageHtml = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitMovieList();
        }
    }
    private void InitMovieList()
    {
        string type = Request["type"];
        string page = Request["page"];
        int p = 1;
        string typeCondition = "";
        //类型不为空且是数字，设置类型条件。否则不加类型条件。
        if (!string.IsNullOrEmpty(type) && int.TryParse(type, out p))
        {
            typeCondition = " where type=" + type;
        }
        else
        {
            type = "30";
        }

        DataRow row = PageData.SelectParamRow("typeCode='movie" + type + "'");
        int total = 1;
        if (row == null)//没有找到，类型不对.设置为默认
        {
            row = PageData.SelectParamRow("typeCode='movie'");
            page = "1";
        }
        Master.SetTitleKeyDesc(row);

        total = int.Parse(row[PageColumn.typeTotalCount].ToString());
        
        PageHtml = PageData.GetPageHtml(total, pageSize, p, "list.aspx?type=" + type + "&page=pageN");

        string sql = "select id, title, case imgLocal when length(imgLocal) > 1 then imgLocal else img end as img, actor, director, year, area from PublishMovie " + typeCondition +
            " order by id desc" ;
        OleDbConnection conn = AccessHelper.GetConnection();
        OleDbCommand cmd = new OleDbCommand(sql, conn);
        OleDbDataReader reader = null;
        try
        {
            conn.Open();
            reader = cmd.ExecuteReader();
            rptMovie.DataSource = reader;
            rptMovie.DataBind();
        }
        finally
        {
            AccessHelper.CloseDbResource(conn, reader);
        }
    }
}
